<?php

/** Sandboxe version of zend search lucene where each module has its own area to create indexes */

require_once 'Zend/Search/Lucene.php';


/**
 * @category   Zend
 * @package    Zend_Search_Lucene
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Myzen_Search_lucene extends Zend_Search_Lucene
{
	
	    /**
     * Create index
     *
     * @param mixed $directory
     * @return Zend_Search_Lucene_Interface
     */
    public static function create($indexName)
    {
        //we get the default path where the indexes are stored
        $basePath = Zend_Registry::get('dt_config')->zend_search_lucene->prependpath;
        
        //we add the module name of the module
        $moduleName = Zend_Controller_Front::getInstance()->getRequest()->getModuleName(); 
        
        $sandBoxedDirectory = $basePath.'/'.$moduleName.'/';
        
        $appendPath = Zend_Registry::get('dt_config')->zend_search_lucene->appendpath;
        if(!empty($appendPath)) $sandBoxedDirectory .= $appendPath.'/';
        
        $sandBoxedDirectory .= $indexName;
        
        Zend_Registry::get('dt_log')->log('creating zend search lucene sandboxed index:'.$sandBoxedDirectory,6);
        //we send it to the parent for creation
        return parent::create($sandBoxedDirectory);
        
    }

    /**
     * Open index
     *
     * @param mixed $directory
     * @return Zend_Search_Lucene_Interface
     */
    public static function open($indexName)
    {	
        //we get the default path where the indexes are stored
        $basePath = Zend_Registry::get('dt_config')->zend_search_lucene->prependpath;
        
        //we add the module name of the module
        $moduleName = Zend_Controller_Front::getInstance()->getRequest()->getModuleName(); 
        
        $sandBoxedDirectory = $basePath.'/'.$moduleName.'/';
        
        $appendPath = Zend_Registry::get('dt_config')->zend_search_lucene->appendpath;
        if(!empty($appendPath)) $sandBoxedDirectory .= $appendPath.'/';
        
        $sandBoxedDirectory .= $indexName;
        
        Zend_Registry::get('dt_log')->log('opening zend search lucene sandboxed index:'.$sandBoxedDirectory,7);
        

        
        //we send it to the parent for creation
        return parent::open($sandBoxedDirectory);
    }
    
    
    public static function switchAnalyzerToEnglishText() {
    	require_once 'Myzen/Search/Lucene/StandardAnalyzer/Analyzer/Standard/English.php';
    	Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());    	
    	
    }
    
    public static function switchAnalyzerToDefault() {    
    	Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive());
    }
    
}